package network;

import javax.net.ssl.HttpsURLConnection;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;

/**
 * @author mubei
 * @date 2021/12/5
 * @description
 */
public class URLDownload {

    public static void main(String[] args) throws Exception {
        URL url = new URL("https://m801.music.126.net/20211205122411/a1b30bc974fa39e3fd3dfd06906380c5/jdyyaac/035d/0e0e/0359/479bda0f399dcc48a0fb439a84c44a38.m4a");
        HttpsURLConnection urlConnection = (HttpsURLConnection)url.openConnection();


        InputStream inputStream = urlConnection.getInputStream();
        String filePath = "D:\\date\\distable\\practice\\code\\basic\\src\\main\\java\\network/love.m4a";

        byte bytes[] = new byte[1024];
        int len = 0;
        FileOutputStream outputStream = new FileOutputStream(filePath);
        while((len = inputStream.read(bytes))!=-1){
            outputStream.write(bytes,0,len);
        }

        outputStream.close();
        inputStream.close();
        urlConnection.disconnect();
    }
}
